<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>后台登录</title>
		<link rel="stylesheet" href="layui/css/layui.css">
		<link rel="stylesheet" href="static/css/style.css">
		<link href="favicon.ico" rel="shortcut icon">
	</head>

	<body style="background-color: #ddd;">
		<form class="layui-form" action="" style="margin-top: 200px;">
			<div class="login">
				<div class="layui-form-item">
					<h2 class="tit">后台登录</h2>
				</div>
				<div class="layui-form-item">
					<input type="text" id="phone" name="uname" lay-verify="uname" autocomplete="off" placeholder="请输入用户名" class="layui-input">
				</div>
				<div class="layui-form-item">
					<input type="password" id="password" name="pass" lay-verify="pass" autocomplete="off" placeholder="请输入密码" class="layui-input">
				</div>
				<div class="layui-form-item">
					<button type="button" class="layui-btn" lay-submit="" lay-filter="login" style="width:100%;">登录</button>
				</div>
			</div>
		</form>
		<script src="layui/layui.js"></script>
		<script src="js/common.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="layer-v3.1.1/layer/mobile/layer.js"></script>
		<script>
			layui.use('form', function() {
				var $ = layui.jquery,
					form = layui.form;
				form.verify({
					uname: function(value) {
						if(value == '') {
							return '用户名不能为空';
						}
					},
					pass: function(value) {
						if(value == '') {
							return '密码不能为空';
						}
					}
				});
				$(".layui-btn").click(function() {
					var phone = $("#phone").val();
					var pwd = $("#password").val();
					if($.trim(phone) != "" && $.trim(pwd) != "") {
						$.ajax({
							type: "POST", //提交方式 
							url: baseurl + "/user/login", //路径
							dataType: 'json',
							data: {
								phone: phone,
								password: pwd
							}, //数据，这里使用的是Json格式进行传输 
							success: function(data) { //返回数据根据结果进行相应的处理 
								if(data.meta.code == 200) {
									localStorage.clear();
									localStorage.setItem("userId", data.data.id);
									localStorage.setItem("userName", data.data.name);
									localStorage.setItem("role", data.data.role);
									localStorage.setItem("status", data.data.status);
									localStorage.setItem("address", data.data.address);
									window.location.href = "index.html";
								} else {
									layer.alert(data.meta.msg)
								}
							},
							error: function(e) {
								layer.alert("登录失败")
							}
						});
					}

				})
			});
		</script>
	</body>

</html>